#include <bits/stdc++.h>
using namespace std;
const string S1 = "Server" , S2 = " Client";
int st1[] = { 255 , 255 , 255 , 255 , 65535 };
char st2[] = { '.' , '.' , '.' , ':' };
map < string , int > m;
bool getss( string s ){
	int l = s.size() , a[5] = {0} , j = 0;
	bool p;
	for ( int i = 0 ; i < 4 ; i ++ ){
		p = s[j] == '0';
		while ( j < l && s[j] >= '0' && s[j] <= '9' )
			a[i] = a[i] * 10 - '0' + s[j ++];
		if ( ( ( a[i] ^ 0 ) && p ) || j >= l || s[j] != st2[i] || a[i] > st1[i] ) return false;
		j ++;
	} 
	while ( j < l ) a[4] = a[4] * 10 - '0' + s[j ++];
	return a[4] <= st1[4];
}
int main(){
	freopen( "network.in"  , "r" , stdin );
	freopen( "network.out" , "w" , stdout );
	string s , s1;
	int n;
	cin >> n;
	//getline ( cin , s );
	for ( int i = 1 ; i <= n ; i ++ ){
		cin >> s >> s1;
		if ( ! getss( s1 ) ){
			puts( "ERR" );
			continue;
		}
		if ( s == S1 ){
			if ( m[s1] ) printf ( "FAIL\n" );
			else m[s1] = i , printf ( "OK\n" );
		}
		else {
			if ( m[s1] ) printf ( "%d\n" , m[s1] );
			else printf ( "FAIL\n" );
		}
	}
	return 0;
}
